home *** CD-ROM | disk | FTP | other *** search
- #! /bin/perl
-
- # This script compares the contents of two zone files, excluding the
- # second line (serial) and all comments. This is a temporary tool for
- # giving me some confidence before installing my new zone-generating
- # script.
- #
- # Philip Hazel, September 2, 1993.
-
-
-
- # ******** Get next non-comment, non-blank line ********
-
- sub next_one{
- for (;;)
- {
- return 0 if (!($one = <ONE>));
- last if substr($one, 0, 1) ne ";" && $one !~ /^\s*$/;
- }
- return 1;
- }
-
- sub next_two{
- for (;;)
- {
- return 0 if (!($two = <TWO>));
- last if substr($two, 0, 1) ne ";" && $two !~ /^\s*$/;
- }
- return 1;
- }
-
-
- # ******** Compare two lines ********
-
- sub check{
- @fields_one = split(/\s+/, $one);
- @fields_two = split(/\s+/, $two);
-
- if ($#fields_one != $#fields_two)
- {
- print "** Different number of fields in lines:\n";
- print "** $one";
- print "** $two";
- die "** Giving up\n";
- }
-
- for ($i = 0; $i <= $#fields_one; $i++)
- {
- if ($fields_one[$i] ne $fields_two[$i])
- {
- print "** Lines don't match:\n";
- print "** $one";
- print "** $two";
- die "** Giving up\n";
- }
- }
- }
-
-
-
- # ******** The Main Program ********
-
- open(ONE, $ARGV[0]) || die "$ARGV[0] failed to open";
- open(TWO, $ARGV[1]) || die "$ARGV[1] failed to open";
-
- # Get the first lines & check them
-
- do next_one();
- do next_two();
- do check();
-
- # Skip the second lines
-
- do next_one();
- do next_two();
-
- # Do the rest of the file
-
- for (;;)
- {
- if (! &next_one())
- {
- if (&next_two())
- {
- print "** First file ends before the second\n";
- die "** Giving up\n";
- }
- else { last; }
- }
-
- else
- {
- if (! &next_two())
- {
- print "** Second file ends before the first\n";
- die "** Giving up\n";
- }
- else { do check(); }
- }
- }
-
-